package com.bwie.common.handle;

import com.bwie.common.exception.CustomException;
import com.bwie.common.result.Result;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * TODO 全局异常处理器
 */
@Log4j2
@RestControllerAdvice
public class GlobalExceptionHandler {

    /**
     * 自定义异常处理器
     */
    @ExceptionHandler(CustomException.class)
    public Result customExceptionHandler(CustomException e) {
        log.error("功能异常，异常信息：{}", e.getMessage());
        return Result.error(e.getCode(),  e.getMessage());
    }
}
